<?php
/**
 * Created by PhpStorm.
 * User: zcw
 * Date: 2020/4/1
 * Time: 下午1:54
 */
namespace globalunit\utils;

class MysqlLocker
{
    private $is_autocommit = false;
    private $mysql = null;

    public function __construct($mysql)
    {
        $this->mysql = $mysql;
        $this->mysql->autocommit(false);
    }

    public function getautocommit()
    {
        return $this->is_autocommit;
    }

    public function autocommit($mode)
    {
        $this->is_autocommit = $mode;
    }

    public function  __destruct()
    {
        if($this->is_autocommit === false){
            $this->mysql->rollback();
        }else{
            $this->mysql->commit();
        }
        $this->mysql->autocommit(true);
    }
}

